<template>
  <div class="updata">
    <mt-header fixed>
      <router-link to="/my_person" slot="left">
        <mt-button icon="back">返回</mt-button>
      </router-link>
    </mt-header>
    <div class="main">
      <mt-field :attr="{ minlength: 6}" label="密码" placeholder="请输入密码" v-model="password"></mt-field>
      <mt-field :attr="{ minlength: 6}" label="新密码" placeholder="请输入新密码" type="password" v-model="newPassword"></mt-field>
    </div>
    <mt-button class="btn" type="danger" size="large" @click="upClick()">确认修改</mt-button>
  </div>
</template>
<script>
import { Toast, Header } from "mint-ui";
import { updataPsd } from "../services/product_type";
import cookie from "js-cookie";

export default {
  name: "updataPsd",
  data() {
    return {
      password: "",
      newPassword: ""
    };
  },
  methods: {
    upClick() {
      if (this.password === "") {
        Toast({
          message: "请输入密码",
          position: "middle",
          duration: 2000
        });
        return;
      }
      if (this.newPassword === "") {
        Toast({
          message: "请输入新密码",
          position: "middle",
          duration: 2000
        });
        return;
      }
      console.log("aaaaaaaaaa");
      updataPsd({
        userName: cookie.get("userName"),
        password: this.password,
        newPassword: this.newPassword
      })
        .then(res => {
          console.log(res);
          Toast({
            message: res.data.msg,
            position: "middle",
            duration: 2000
          });
          if (res.data.status == "Y") {
            const userName = cookie.get("userName");
            cookie.set("userName", userName, {
              expires: -1
            });
            this.$router.push({ name: "login" });
          }
        })
        .catch(err => {
          console.log(err);
        });
    }
  }
};
</script>
<style scoped>
.main{
  position: relative;
  top: 80px;
}
.btn{
  position: relative;
  margin-top: 120px;
}
</style>


